Current Location: Home> Function Categories> date_sub

date_sub

DateTime::sub - Subtract a certain amount of days, months, years, hours, minutes, and seconds to a DateTime object
Name:date_sub
Category:Date and time
Programming Language:php
One-line Description:Subtract the day, month, year, hour, minute, and second from the specified date.

Definition and usage

date_sub() function subtracts the day, month, year, hour, minute, and second from the specified date.

Example

Subtract 4 days from September 29, 2016:

 <?php
$date = date_create ( "2016-09-29" ) ;
date_sub ( $date , date_interval_create_from_date_string ( "4 days" ) ) ;
echo date_format ( $date , "Ymd" ) ;
?>

Try it yourself

grammar

 date_sub ( object , interval ) ;
parameter describe
object Required. Specifies the DateTime object returned by date_create() .
interval Required. Specifies the DateInterval object.
Similar Functions